<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>电机日志</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/admin/css/other/department.css"/>
</head>
<body class="pear-container">
<!--<div class="layui-card">-->
<!--    <div class="layui-card-body">-->
<!--        <div class="layui-row layui-col-space15">-->
<!--            <div class="layui-col-md2">-->
<!--                <button type="button" class="pear-btn layui-btn-fluid  layui-btn-primary layui-border-black">-->
<!--                    &lt;!&ndash;                    <i class="layui-icon layui-icon-add-circle" style="font-size: 17px"></i>&ndash;&gt;-->
<!--                    <img src="/img/删除.png" alt="" style="height: 18px;">-->
<!--                    清除日志-->
<!--                </button>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">电机方向</label>
                    <div class="layui-input-inline">
                        <select name="type" lay-search>
                            <option value=""></option>
                            <option value="1">正转</option>
                            <option value="2">反转</option>
                            <option value="3">停止</option>
                            <option value="4">开门</option>
                            <option value="5">关门</option>
                            <option value="6">盘库</option>
                            <option value="7">门停止</option>
                            <option value="8">故障复位</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="userName" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="search-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">运行日志</li>
                <!--                <li>操作日志</li>-->
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table style="margin-top: 10px;" id="logTable" lay-filter="logTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script type="text/html" id="log-bar">
    {{#if (d.success == true) { }}
    <button class="pear-btn pear-btn-sm pear-btn-success" lay-event="edit"><i class="layui-icon layui-icon-ok"></i>
        成功
    </button>
    {{# }else if(d.success == false){ }}
    <button class="pear-btn pear-btn-sm pear-btn-danger" lay-event="error"><i class="layui-icon layui-icon-help"></i>
        异常
    </button>
    {{# } }}
</script>

<script type="text/html" id="log-createTime">
    {{layui.util.toDateString(d.createTime,  "yyyy-MM-dd HH:mm:ss")}}
</script>

<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'element'], function () {
        let table = layui.table;
        let form = layui.form;
        let element = layui.element;

        let MODULE_PATH = "/system/logging/";

        let cols = [
            [
                {title: '用户名', field: 'user_name', align: 'center'},
                {
                    title: '操作类型', field: 'type', align: 'center', templet: function (d) {
                        if (d.type == 1) {
                            return "正传";
                        }else if (d.type == 2) {
                            return "反转";
                        }else if (d.type == 3) {
                            return "停止";
                        }else if (d.type == 4) {
                            return "开门";
                        }else if (d.type == 5) {
                            return "关门";
                        }else if (d.type == 6) {
                            return "盘库";
                        }else if (d.type == 7) {
                            return "门停止";
                        }else if (d.type == 8) {
                            return "故障复位";
                        }
                    }
                },

                {title: '操作详情', field: 'operation', align: 'center'},
                {title: '操作时间', field: 'create_time', align: 'center'},
                // {title: '操作地址', field: 'operateAddress', align: 'center'},
                // {title: '操作系统', field: 'systemOs', align: 'center'},
                // {title: '访问时间', field: 'createTime', templet: '#log-createTime', align: 'center'},
                // {title: '操作人', field: 'operateName', align: 'center'},
                // {title: '访问状态', toolbar: '#log-bar', align: 'center', width: 150}
            ]
        ]
        //请求渲染表格获取数据
        tableIns = table.render({
            elem: '#logTable',
            url: '/motor/log/list',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: true,
            id: 'testReload',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            //解决页码的问题
            done: function (res) {
                // 获得当前页码
                var brforeCurr = tableIns.config.page.curr;
                // 获得当前页的记录数
                var dataLength = table.cache['testReload'].length;
                var count = res.count; // 获得总记录数
                //如果当前页的记录数为0并且总记录数不为0
                if (dataLength == 0 && count != 0) {
                    // 刷新表格到上一页
                    table.reload("testReload", {
                        page: {
                            curr: brforeCurr - 1
                        }
                    });
                }
            }
        });
        // 刷新按钮
        window.refresh = function (param) {
            table.reload('testReload');
        }
        table.on('toolbar(logTable)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });
        // 搜索
        form.on('submit(search-query)', function (data) {
            table.reload('testReload', {where: data.field})
            return false;
        });

        window.error = function (obj) {
            layer.open({
                type: 1,
                title: '异常信息',
                shade: 0,
                area: ['450px', '350px'],
                content: '<div class="pear-container"><div class="layui-card"><div class="layui-card-body">' + obj.data['error'] + '</div></div></div>'
            });
        }
    })
</script>
</html>